package com.loop.unclelend.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.loop.unclelend.databinding.UncleDialogTipsBinding
import com.loop.unclelend.pro.ProDialog
import com.loop.unclelend.utils.event.UncleEventHelper
import com.loop.unclelend.utils.event.UncleEventType

/**
 * UncleLend
 * @Author wwdeng
 * @CreateTime: 2024/9/4 15:41
 * @Annotation：提示dialog
 */
class Dialog_Tips: ProDialog {

    private lateinit var binding: UncleDialogTipsBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = UncleDialogTipsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(binding.btnCancel) //取消
        setOnClickListener(binding.btnOk) //ok
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun setTipsEventRemark(remark: String){
        eventRemark = remark
    }

    /**
     * 设置提示图标
     */
    fun setTipsIconResource(resId: Int){
        binding.imgTips.setImageResource(resId)
    }

    /**
     * 设置提示title
     */
    fun setTitleText(title: String){
        binding.txtTipsTitle.text = title
    }

    /**
     * 设置提示语
     */
    fun setTipsText(tips: String){
        binding.txtTips.text = tips
    }

    /**
     * 设置显示一个按钮或两个按钮
     */
    fun isDoubleButton(isDouble: Boolean){
        if (isDouble){//显示两个图标
            binding.btnCancel.visibility = View.VISIBLE
            binding.btnOk.visibility = View.VISIBLE
        } else {
            binding.btnCancel.visibility = View.GONE
            binding.btnOk.visibility = View.VISIBLE
        }
    }

    /**
     * 设置取消文字
     */
    fun setBtnCancelText(text: String){
        binding.btnCancel.text = text
    }

    /**
     * 设置取消按钮背景
     */
    fun setBtnCanceBackgroundResource(resId: Int){
        binding.btnCancel.setBackgroundResource(resId)
    }

    /**
     * 设置ok文字
     */
    fun setBtnOkText(text: String){
        binding.btnOk.text = text
    }

    /**
     * 设置ok按钮背景
     */
    fun setBtnOkBackgroundResource(resId: Int){
        binding.btnOk.setBackgroundResource(resId)
    }

    /**
     * 设置两个按钮背景
     */
    fun setButtonDoubleBackgroundResource(leftResId: Int,rightResId: Int){
        binding.btnCancel.setBackgroundResource(leftResId)
        binding.btnOk.setBackgroundResource(rightResId)
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        UncleEventHelper.addUncleRequestEventAction(UncleEventType.DIALOG.UNCLE_DIALOG_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        UncleEventHelper.addUncleRequestEventAction(UncleEventType.DIALOG.UNCLE_DIALOG_TIPS_DISMISS,eventRemark)
    }
}